<?
/**
*鼓浪屿轮渡
*2015-03-17 by pzp
**/
class Ferry_gly{
	private $USER ='piaofutong'; //账号
	private $PWD ='piaofutong'; //密码
	// private $reURL = 'http://jtsvn.eicp.net:3326/t/today/fx/';//提交地址
	private $reURL = 'http://112.124.70.160/t/today/fx/';//提交地址
	
	//查询航线信息
	public function getFlightLine(){ 
		$action = 'getFlightLine.do';
		$str_array = array(
					'ip' =>'2.2.2.2'
		);
		$response = $this->Ferry_POST($action,$str_array);
		return $response;
	}
	
	//查询余票接口
	public function getDailyFlight($number){
		$number = $number?$number:"DP";
		$action = 'getDailyFlight.do';
		$str_array = array(
					'ip' =>'2.2.2.2',
					'fightLineNumber'=>$number
		);
		$response = $this->Ferry_POST($action,$str_array);
		return $response;
	}
	
	//查询隔天余票接口
	public function getDailyFlightOther(){
		$action = 'getDailyFlightOther.do';
		$str_array = array(
					'ip' =>'2.2.2.2',
					'fightLineNumber'=>"DP",
					'date'=>'2015-03-21'
		);
		$response = $this->Ferry_POST($action,$str_array);
		return $response;
	  
	}
	
	
	//推送订单接口
	public function saveSaleOrder(){
		$action = 'saveSaleOrder.do';
		$content =<<<XML
<saleOrder>
<sno></sno>
<ebusinessOrder>pzp002</ebusinessOrder>
<flightNumber>DP0750</flightNumber>
<departTime>2015-03-20 07:50:00</departTime>
<seat>3</seat>
<amount>15</amount>
<list>
<item>
<ticket>
<id>9652EE647B814F9A8F79B4061E1FDB2B</id>
<name>全价票35</name>
<price>25</price>
<number></number>
</ticket>
<person>
<identityType>身份证</identityType> 
<name>王五</name>
<identityNO>350322198711113015</identityNO>
<phoneNumber>15959110796</phoneNumber>
<children>1</children>
</person>
</item>
</list>
</saleOrder>
XML;
		// print_r($content);
		$str_array = array(
					'ip' =>'2.2.2.2',
					'content'=>$content
		);
		$response = $this->Ferry_POST($action,$str_array);
		return $response;
	}
	
	// 支付成功接口
	public function payForSaleOrder(){
		$action = 'payForSaleOrder.do'; 
		$str_array = array(
					'sno'=>'1503201748101537', //1503181426387077
					'payment'=>'在线支付'
		);
		$response = $this->Ferry_POST($action,$str_array);
		return $response;	
	}
	
	//取消回调(支付)接口
	public function saveCancel(){
		$action = 'saveCancel.do';
		$str_array = array(
					'sno'=>'1503201809430350',
		);
		$response = $this->Ferry_POST($action,$str_array);
		return $response;	
	}
	
	//查询订单接口
	public function findSaleOrder(){
		$action = 'findSaleOrder.do';
		$str_array = array(
					'sno'=>'pzp001',
					'identityCardNO'=>'350321199108230123'
		);
		$response = $this->Ferry_POST($action,$str_array);
		return $response;		
	}	
	
	//退票接口
	public function saveReturn(){
		$action = 'saveReturn.do';
		$str_array = array(
					'sno'=>'1503201748101537',
					'identityCardNO'=>'350322198711113011'
		);
		$response = $this->Ferry_POST($action,$str_array);
		return $response;	
	
	}
	

	
	//提交数据
	public function Ferry_POST($action,$str_array){
		$str_array['USER'] = $this->USER;
		$str_array['PWD'] = $this->PWD;
		$post_data= http_build_query($str_array);
		$request_URL=$this->reURL.$action;
		$ch = curl_init(); 
		curl_setopt($ch, CURLOPT_POST, 1); 
		curl_setopt($ch, CURLOPT_HEADER, 0); 
		curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);  
		curl_setopt($ch, CURLOPT_URL,$request_URL); 	
		curl_setopt($ch, CURLOPT_USERPWD, "{$this->USER}:{$this->PWD}"); 
		curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); 
		curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
		$result = curl_exec($ch);
		if (!$result) {  
			return curl_error($ch);  
		}else {  
			return $result;  
		}     	
	}

}
// $gly_client = new Ferry_gly();
// $getFlightLine = $gly_client->getFlightLine(); print_r('查询航线'.$getFlightLine);//查询航线信息
// $getDailyFlight = $gly_client->getDailyFlight(); print_r('查询余票'.$getDailyFlight);//查询余票
// $getDailyFlightOther = $gly_client->getDailyFlightOther(); print_r('查询隔天余票',$getDailyFlightOther);//查询隔天余票
// $saveSaleOrder = $gly_client->saveSaleOrder(); print_R('提交订单'.$saveSaleOrder); //推送订单
// $payForSaleOrder = $gly_client->payForSaleOrder();print_r('支付订单'.$payForSaleOrder); //支付成功接口
// $saveCancel = $gly_client->saveCancel();print_r('取消支付'.$saveCancel);
// $findSaleOrder = $gly_client->findSaleOrder();print_r('查询订单'.$findSaleOrder);
// $saveReturn = $gly_client->saveReturn();print_r('取消订单'.$saveReturn);
?>